import request from "@/utils/request";
import { CategoryFormDto, CategoryQuery, CategoryVo } from "./type";

const api: string = "/category";

/**
 * 查询分类列表数据
 */
export function getCategoryOptionsApi(): Result<SelectBox[]> {
  return request({
    url: `${api}/options`,
    method: "get",
  });
}

/** 分页获取标签 */
export function getCategoryPageApi(
  params: CategoryQuery
): PageResult<CategoryVo> {
  return request({
    url: `${api}/page`,
    method: "get",
    params,
  });
}

/** 查询表单信息 */
export function getCategoryFormApi(id: number): Result<CategoryFormDto> {
  return request({
    url: `${api}/${id}/form`,
    method: "get",
  });
}

/** 增加分类 */
export function addCategoryApi(data: CategoryFormDto): Result<void> {
  return request({
    url: `${api}`,
    method: "post",
    data,
  });
}

/** 修改分类 */
export function updateCategoryApi(data: CategoryFormDto): Result<void> {
  return request({
    url: `${api}`,
    method: "put",
    data,
  });
}

/** 删除分类 */
export function deleteCategoriesApi(ids: string): Result<void> {
  return request({
    url: `${api}/${ids}`,
    method: "delete",
  });
}
